package pl.hurtdroid;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.R.string;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class hurtdroidact extends Activity {
	
	
	TextView nameTxt;
	TextView surnameTxt;
	TextView phoneTxt;
	
	private void  GetDataFromServer() {
		
		HttpClient httpclient = new DefaultHttpClient();
		Uri url = new Uri.Builder().scheme("http")
				.authority("deprecated.pl")
				.appendQueryParameter("json", "Auth")
				.appendQueryParameter("uid", "1")
				
				// .appendQueryParameter("id",
				// Integer.toString(document.getCurrentStation().getId()))
				// .appendQueryParameter("jsonString",
				// gasPrices.toString()
				// )
				.build();

		HttpPost httppost = new HttpPost(url.toString());

		try {
			// Add your data
			// Execute HTTP Post Request
			HttpResponse response = httpclient.execute(httppost);
			HttpEntity httpEntity = response.getEntity();
			String line = EntityUtils.toString(httpEntity);
			try {
				JSONObject object = (JSONObject) new JSONTokener(line)
						.nextValue();
				String isOK = object.getString("RESULT");
				//if (object.getString("RESULT") == "OK") {

					nameTxt.setText(object.getString("Imie"));
					surnameTxt.setText(object.getString("Nazwisko"));
					phoneTxt.setText(object.getString("Telefon"));
					
			//	}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
			 e.printStackTrace();

			}

		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
//			isOK = false;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
//			isOK = false;
		}

	} 
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
        nameTxt = (TextView)findViewById(R.id.nameText);
        surnameTxt = (TextView)findViewById(R.id.surnameText);
        phoneTxt = (TextView)findViewById(R.id.telephoneText);
        GetDataFromServer();
    }
}